
//
// 110527 - AH - (Garage) Created.
// 110529 - AH - (Victoria) Missing java doc.

package org.soekrat.gui.swing.studio;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JPanel;

import org.soekrat.engine.Soekrat2Engine;
import org.soekrat.engine.forest.Forest;
import org.soekrat.engine.ontology.Sentence;
import org.soekrat.engine.ontology.SentenceBasedOntology;
import org.soekrat.engine.sparewheel.SpareWheel;
import org.soekrat.gui.swing.rethor.SentenceBasedOntologyView;

/**
 * <p>
 *   {@link RatStudioView} to show
 *   {@link SentenceBasedOntologyView} in a dockable way.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
public final class RethorRatStudioView extends RatStudioView 
{
  private final SentenceBasedOntologyView m_sbov=
    new SentenceBasedOntologyView();
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param engine {@link Soekrat2Engine} interfaced.
   */
  public RethorRatStudioView(final Soekrat2Engine engine) 
  {
    super("Rethor", engine);
    
    if (engine==null)
    {
      throw new NullPointerException("engine");
    }
    
    JPanel c=getContentPanel();
    c.setLayout(new BorderLayout());
    c.add(m_sbov, BorderLayout.CENTER);
    
    SpareWheel sw=engine.getSpareWheel();
    Forest forest=sw.getForest();
    m_sbov.setOntology(forest);
    
    JPanel buttons=new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttons.add
    (
      new JButton
      (
        new AbstractAction("Refresh")
        {
          public void actionPerformed(ActionEvent e)
          { 
            SentenceBasedOntology ontology=engine.getSpareWheel().getForest();
            m_sbov.setOntology(ontology);
          }
        }
      )
    );
    buttons.add
    (
      new JButton
      (
        new AbstractAction("Delete") 
        {
          public void actionPerformed(ActionEvent e)
          {
            Sentence s=m_sbov.getSelected();
            if (s!=null)
            {
              m_sbov.deleteSentence(s);
            }
          }
        }
      )
    );
    c.add(buttons, BorderLayout.SOUTH);
  }
  
}
